package com.springBoot.springBootSysCore.modules.entity.system;


import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.springBoot.springBootSysCore.common.comment.annotation.MyComment;
import com.springBoot.springBootSysCore.common.persistence.DataEntity;
/**
 * 机构
 * @author Autism
 *
 */
@Entity
@Table(name="SYS_ORGANIZATION")
@MyComment("机构表")
@Component("sysOrganization")
public class SysOrganization extends DataEntity<SysOrganization>{
	private static final long serialVersionUID = 1L;
	private String name;//机构名称
	private String info;//描述
	private SysOrganization parentOrganizations;//父节点
    private List<SysOrganization> childrenOrganizations;//子节点
	private List<SysUser> sysUsers;//用户
	@Column(name="NAME",length=50)
	@MyComment("机构名称")
	@NotNull(message="机构名称不能为空")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(name="INFO",length=500)//,unique=true
	@MyComment("描述信息")
	public String getInfo() {
		return info;
	}
	public void setInfo(String info) {
		this.info = info;
	}
	@ManyToOne
	@JoinColumn(name="P_ID")
	@MyComment("本机构的父机构ID")
	public SysOrganization getParentOrganizations() {
		return parentOrganizations;
	}
	public void setParentOrganizations(SysOrganization parentOrganizations) {
		this.parentOrganizations = parentOrganizations;
	}
	@OneToMany(cascade={CascadeType.MERGE,CascadeType.PERSIST}, mappedBy = "parentOrganizations")
	@JsonIgnore
	public List<SysOrganization> getChildrenOrganizations() {
		return childrenOrganizations;
	}
	public void setChildrenOrganizations(List<SysOrganization> childrenOrganizations) {
		this.childrenOrganizations = childrenOrganizations;
	}
	@ManyToMany(cascade={CascadeType.MERGE,CascadeType.PERSIST},mappedBy="orgList")
	@JsonIgnore
	public List<SysUser> getSysUsers() {
		return sysUsers;
	}
	public void setSysUsers(List<SysUser> sysUsers) {
		this.sysUsers = sysUsers;
	}
}
